package com.example.daojia.frametest.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.daojia.frametest.R;
import com.jakewharton.rxbinding2.view.RxView;

import org.reactivestreams.Subscription;

import java.util.Observable;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

@Route(path = "/app/rxBinding")
public class rxBinding extends AppCompatActivity {
    @BindView(R.id.noRepeat)
    Button noRepeat;
    @BindView(R.id.longClick)
    Button longClick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rx_binding);
        ButterKnife.bind(this);
        initview();
    }

    private void initview() {
        RxView.clicks(noRepeat)
                .throttleFirst(2, TimeUnit.SECONDS)
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        Toast.makeText(rxBinding.this, "防止重复点击，2秒间隔点击有效", Toast.LENGTH_SHORT).show();
                    }
                });

        RxView.longClicks(longClick)
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {
                        Toast.makeText(rxBinding.this, "长点击事件，1秒点击有效", Toast.LENGTH_SHORT).show();
                    }
                });

    }
}
